package com.itlzh.mall.user.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itlzh.mall.common.entity.UserInfo;
import com.itlzh.mall.user.mapper.IUserInfoMapper;
import com.itlzh.mall.user.service.IUserInfoService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserInfoServiceImpl extends ServiceImpl<IUserInfoMapper, UserInfo> implements IUserInfoService {
    //按登录名查询用户--初步使用条件构造器
    @Override
    public UserInfo queryByLoginName(String username) {
        //创建条件构造器
        LambdaQueryChainWrapper<UserInfo> wrapper
                = new LambdaQueryChainWrapper<>(getBaseMapper());
        //构建条件并获取查询结果
        UserInfo userInfo = wrapper.eq(UserInfo::getUsername, username)
                .select(UserInfo::getId,UserInfo::getUsername,UserInfo::getPassword,UserInfo::getNickName)
                .one();
        return userInfo;
    }

    //按创建时间和状态查询用户--使用条件构造器
    @Override
    public List<UserInfo> listByCreateTimeAndStatus(LocalDateTime start, LocalDateTime end, Integer status) {
        //创建条件构造器
        LambdaQueryChainWrapper<UserInfo> wrapper=
                new LambdaQueryChainWrapper<>(getBaseMapper());
        List<UserInfo> list = wrapper.between(UserInfo::getCreateTime, start, end)
                .eq(UserInfo::getStatus, status)
                .list();
        return list;
    }

    public UserInfo queryByUsername(String username){
        return queryByUsername( username);
    }


}
